package datasv.courseSelect_datasv;

import data.datafactory.DatabaseOperator;
import resultmessage.CourseSelectRM;

public class AddSelectRecord {
	public static void main(String[] args) {
		System.out.println(new AddSelectRecord().addSelectRecord("00101130010", "001131002"));
	}
	public CourseSelectRM addSelectRecord(String courseID,String studentID){
		return addInSql(courseID, studentID);
	}
	private CourseSelectRM addInSql(String courseID,String studentID){
		String collegeID=courseID.substring(0, 3);
		DatabaseOperator op=new DatabaseOperator("college"+collegeID);
		if(!op.ifDatabaseExist()||!op.ifIDExist("course_list", courseID)){
			return CourseSelectRM.COURSEID_NOT_EXIST;
		}
		DatabaseOperator op2=new DatabaseOperator("college"+studentID.substring(0,3));
		if(!op2.ifIDExist("student_list", studentID)){
			return CourseSelectRM.STUDENT_NOT_EXIST;
		}
		String[][] info={{"id",courseID},{"studentID",studentID}};
		if(op.addRowWithKeys("id", "studentID", info, "course_select_record")){
			return CourseSelectRM.SUCCESS;
		}
		return CourseSelectRM.STUDENT_EXIST;
	}
}
